<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/commons/jsp/taglibs.jsp"%>
<%@ taglib uri="http://www.framework.com/taglib/tree" prefix="tree"%>
<%@taglib prefix="frame" uri="http://www.framework.com/taglib"%>
<form name="addDataForm" id="addDeptDataForm" method="post" action="${ctx}/framework/dept/save">
    <input type="hidden" name="id" value="${dept.id}"/>
	<input type="hidden" name="createTime" value="<fmt:formatDate value='${dept.createTime}' pattern='yyyy-MM-dd HH:mm:ss'/>"/>
	<input type="hidden" name="createrName" value="${dept.createrName}"/>
    <input type="hidden" name="createrId" value="${dept.createrId}"/>
    
    <%-------------------------------获取双审(start)--------------------------------------%>   
    <%--<input type="hidden" name="doubleAuditable" value="${dept.doubleAuditable}"/>--%>
    <%-------------------------------获取双审(end)--------------------------------------%>   
	<table class="infoTable">
		<tbody>
		<tr>
			<th align="right" width="10%">部门名称</th>
			<td><input name="name" class="easyui-validatebox" size="30" value="${dept.name}" data-options="required:true" maxlength="50"/>
			</td>
			<th align="right" width="10%">上级部门</th>
			<td>
			<input name="pName" class="easyui-validatebox" id="pName" size="30" value="${dept.pName}" data-options="required:true,missingMessage:'请选择上级部门'" maxlength="50" readonly="readonly"/>
			<input type="hidden" name="pid" id="deptPid" class="easyui-validatebox" size="30" value="${dept.pid}"/>
			
			<span id="pDept" style="width: 100px;height: 100px;"><a href="javascript:void(0);" onclick="selectParentDept()"><img src="${ctx}/commons/themes/icons/icon3.gif" border="0" title="上级部门"/></a></span>
			</td>
		</tr>
 		<tr id="deptType" colspan='3'></tr>
		</tbody>
	</table>
	<tree:deptTree ctx="${ctx}" deptIds="deptPid" deptNames="pName" selectMethod="single" />
</form>
<script type="text/javascript">
	function selectParentDept(){
		seldeptPidDeptTree($('#deptPid').val());
		$('#deptPidDeptTreeDialog').dialog('open');
	}
</script>

<div id='deptPidTool' style='padding:5px;display: none;'>
	<div style='margin-bottom:5px;'>
		节点名称
		<input type='text' id='seldeptPidDeptTreeName' name='treeName'/>
			&nbsp;&nbsp;
			<a href='javascript:void(0);' onclick='seldeptPidDeptTree();' class='easyui-linkbutton' >查询</a>
	</div>
</div>
<div id="deptPidDeptTreeDialog" class="easyui-dialog" 
	title="部门选择树" style="width:320px;height:442px;padding:8px;padding-top: 0px;"
	data-options="iconCls: 'icon-dept',method:'post',closed:true,modal: true,toolbar:'#deptPidTool',
	buttons: [{	
		text:'选择',	
		iconCls:'icon-ok',	
		handler:function(){
			getSelectdeptPidDeptNode();	
		}
	},{	
		text:'取消',
		iconCls:'icon-cancel',	
		handler:function(){		
			$('#deptPidDeptTreeDialog').dialog('close');	
		}
	}]">
	<ul id="deptPidDeptTree" class="easyui-tree" 
			data-options="url:'',
				method:'get',
				animate:true,
				loadFilter:function(data){
					ids=data.selIds;
					return data.tree;
				},
				formatter:function(node){	
					if(ids != undefined){		
						for(var i=0;i<ids.length;i++){			
							if(node.id == ids[i]){				
								return '<span style=\'color:red;font-weight: bold;\'>'+node.text+'</span>';	
							}		
						}	
					}	
					return node.text;
				}">
	</ul>
</div>
<script type="text/javascript">
	var ids;
	function getSelectdeptPidDeptNode(){	
		var node = $('#deptPidDeptTree').tree('getSelected');
		if(node == null){		
			$.messager.alert('提示','请选择机构节点！','info');	
		}else{		
			$('#pName').val(node.text); 
			$('#pName').focus();		
			$('#deptPid').val(node.id);
			$.ajax({
				type: "get",
				url:  '${ctx}/framework/dept/getDeptType?r='+new Date().getTime(),
				data:'id='+node.id,
				success: function(data,res){
					 $("#deptType").html(data);
					 $.parser.parse("#deptType");
				},
				error: function(res){
					
				}
			});
			$('#deptPidDeptTreeDialog').dialog('close');
		}
	}
	function getSelectsdeptPidDeptNode(){	
		var nodes = $('#deptPidDeptTree').tree('getChecked');	
		var nodeNames = '';
		var nodeIds = '';
		for(var i=0; i<nodes.length; i++){		
			if (nodeNames != '') nodeNames += ',';		
			nodeNames += nodes[i].text;		
			if (nodeIds != '') nodeIds += ',';		
			nodeIds += nodes[i].id;	
		}	
		$('#pName').val(nodeNames);	
		$('#deptPid').val(nodeIds);	
		$('#deptPidDeptTreeDialog').dialog('close');
	}
	function seldeptPidDeptTree(selectIds){
		$('#deptPidDeptTree').tree('options').url='${ctx}/framework/dept/getDeptTreeDialog?nodeName='+encodeURI(encodeURI($('#seldeptPidDeptTreeName').val()))+'&deleteIds ='+selectIds+'&r='+new Date().getTime();
		$('#deptPidDeptTree').tree({onLoadSuccess:function(node, data){
			var node = $('#deptPidDeptTree').tree('find', selectIds);
			debugger;
			if(node){
				$('#deptPidDeptTree').tree('expand', node.target).tree('select', node.target);
			}
		}})
	}
	<c:if test = "${not empty dept}">
		$(function(){
			$.ajax({
				type: "get",
				url:  '${ctx}/framework/dept/getDeptType',
				data:'id=${dept.pid}&type=${dept.type}&deptCode=${dept.deptCode}&deptId=${dept.id}',
				success: function(data,res){
					 $("#deptType").html(data);
					 $.parser.parse("#deptType");
				},
				error: function(res){
					
				}
			});
	});
	</c:if>
</script>
